<?php
namespace api\action\votelog;

use Yii;
use yii\rest\CreateAction as BaseCreateAction;
use yii\helpers\Url;
use common\helpers\Util;

class CreateAction extends BaseCreateAction
{
    public function init()
    {
        parent::init();
    }

    public function run()
    {
        if ($this->checkAccess) {
            call_user_func($this->checkAccess, $this->id);
        }

        /* @var $model \yii\db\ActiveRecord */
        $model = new $this->modelClass([
            'scenario' => $this->scenario,
        ]);


        $model->load(Yii::$app->getRequest()->getBodyParams(), '');
        

        if (!$model->save()) {
            Util::error(implode(',', $model->firstErrors), 502);
        }
        return $model;
    }


}
